package p270jp.pxv.android.advertisement.presentation.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.socdm.p087d.adgeneration.ADG;
import com.socdm.p087d.adgeneration.ADGConsts;
import com.socdm.p087d.adgeneration.ADGListener;
import com.socdm.p087d.adgeneration.nativead.ADGInformationIconView;
import com.socdm.p087d.adgeneration.nativead.ADGNativeAd;
import java.util.Objects;
import p062c4.ViewBindings;
import p064c6.Preconditions;
import p072ce.ViewAdgWrapperBinding;
import p189gn.AbstractC3435a;
import p216hn.Lambda;
import p216hn.Reflection;
import p270jp.pxv.android.R;
import p270jp.pxv.android.legacy.model.GoogleNg;
import p284ke.AdUtils;
import p325m0.MutabilityOwnership;
import p350mp.Timber;
import p376no.Koin;
import p404oo.AbstractC5475a;
import p579vo.Qualifier;
import p603wm.AbstractC6949c;

/* compiled from: NovelNativeADGView.kt */
/* renamed from: jp.pxv.android.advertisement.presentation.view.NovelNativeADGView */
/* loaded from: classes2.dex */
public final class NovelNativeADGView extends FrameLayout implements AbstractC5475a {

    /* renamed from: b */
    public ADG f18818b;

    /* renamed from: a */
    public final AbstractC6949c f18817a = Preconditions.m9801Q(new p312le.NovelNativeADGView(this));

    /* renamed from: c */
    public final AbstractC6949c f18819c = Preconditions.m9802P(1, new C4169b(this, null, null));

    /* compiled from: NovelNativeADGView.kt */
    /* renamed from: jp.pxv.android.advertisement.presentation.view.NovelNativeADGView$a */
    /* loaded from: classes2.dex */
    public static final class C4167a extends ADGListener {

        /* renamed from: a */
        public final Context f18820a;

        /* renamed from: b */
        public final ADG f18821b;

        /* renamed from: c */
        public final AdUtils f18822c;

        /* renamed from: d */
        public final ViewAdgWrapperBinding f18823d;

        /* compiled from: NovelNativeADGView.kt */
        /* renamed from: jp.pxv.android.advertisement.presentation.view.NovelNativeADGView$a$a */
        /* loaded from: classes2.dex */
        public /* synthetic */ class C4168a {

            /* renamed from: a */
            public static final /* synthetic */ int[] f18824a;

            static {
                int[] iArr = new int[ADGConsts.ADGErrorCode.values().length];
                iArr[ADGConsts.ADGErrorCode.EXCEED_LIMIT.ordinal()] = 1;
                iArr[ADGConsts.ADGErrorCode.NEED_CONNECTION.ordinal()] = 2;
                iArr[ADGConsts.ADGErrorCode.NO_AD.ordinal()] = 3;
                f18824a = iArr;
            }
        }

        public C4167a(Context context, ADG adg, AdUtils aVar, ViewAdgWrapperBinding aVar2) {
            MutabilityOwnership.m3745m(aVar, "adUtils");
            this.f18820a = context;
            this.f18821b = adg;
            this.f18822c = aVar;
            this.f18823d = aVar2;
        }

        @Override // com.socdm.p087d.adgeneration.ADGListener
        public void onFailedToReceiveAd(ADGConsts.ADGErrorCode aDGErrorCode) {
            int i = aDGErrorCode == null ? -1 : C4168a.f18824a[aDGErrorCode.ordinal()];
            if (i != 1 && i != 2 && i != 3) {
                this.f18821b.start();
            }
        }

        @Override // com.socdm.p087d.adgeneration.ADGListener
        public void onReceiveAd() {
            this.f18823d.f5396c.setVisibility(8);
        }

        @Override // com.socdm.p087d.adgeneration.ADGListener
        public void onReceiveAd(Object obj) {
            if (obj instanceof ADGNativeAd) {
                ADGNativeAd aDGNativeAd = (ADGNativeAd) obj;
                if (aDGNativeAd.getIconImage() == null) {
                    Timber.f23100a.mo3525d("ADGNativeAd icon image is null so cannot display", new Object[0]);
                    return;
                }
                this.f18823d.f5396c.setVisibility(8);
                AdUtils aVar = this.f18822c;
                Context context = this.f18820a;
                Objects.requireNonNull(aVar);
                MutabilityOwnership.m3745m(context, "context");
                MutabilityOwnership.m3745m(aDGNativeAd, "nativeAdObject");
                View inflate = LayoutInflater.from(context).inflate(R.layout.view_novel_ad_item, (ViewGroup) null, false);
                int i = R.id.cover_image_view;
                ImageView imageView = (ImageView) ViewBindings.m9835b(inflate, R.id.cover_image_view);
                if (imageView != null) {
                    i = R.id.information_icon;
                    FrameLayout frameLayout = (FrameLayout) ViewBindings.m9835b(inflate, R.id.information_icon);
                    if (frameLayout != null) {
                        i = R.id.novel_info_container;
                        if (((LinearLayout) ViewBindings.m9835b(inflate, R.id.novel_info_container)) != null) {
                            i = R.id.novel_item_container;
                            RelativeLayout relativeLayout = (RelativeLayout) ViewBindings.m9835b(inflate, R.id.novel_item_container);
                            if (relativeLayout != null) {
                                i = R.id.sponsored_text_view;
                                TextView textView = (TextView) ViewBindings.m9835b(inflate, R.id.sponsored_text_view);
                                if (textView != null) {
                                    i = R.id.title_text_view;
                                    TextView textView2 = (TextView) ViewBindings.m9835b(inflate, R.id.title_text_view);
                                    if (textView2 != null) {
                                        FrameLayout frameLayout2 = (FrameLayout) inflate;
                                        frameLayout.addView(new ADGInformationIconView(context, aDGNativeAd, true, ADGInformationIconView.Corner.BOTTOM_RIGHT, ADGInformationIconView.BackgroundType.WHITE));
                                        aVar.f20317b.m56j(context, aDGNativeAd.getIconImage().getUrl(), imageView);
                                        textView2.setText(aDGNativeAd.getTitle().getText());
                                        textView.setText(aDGNativeAd.getSponsored().getValue());
                                        aDGNativeAd.setClickEvent(context, relativeLayout, null);
                                        MutabilityOwnership.m3746l(frameLayout2, "binding.root");
                                        this.f18823d.f5395b.addView(frameLayout2);
                                        this.f18821b.setAutomaticallyRemoveOnReload(frameLayout2);
                                        return;
                                    }
                                }
                            }
                        }
                    }
                }
                throw new NullPointerException("Missing required view with ID: ".concat(inflate.getResources().getResourceName(i)));
            }
        }
    }

    /* compiled from: KoinComponent.kt */
    /* renamed from: jp.pxv.android.advertisement.presentation.view.NovelNativeADGView$b */
    /* loaded from: classes2.dex */
    public static final class C4169b extends Lambda implements AbstractC3435a<AdUtils> {

        /* renamed from: a */
        public final /* synthetic */ AbstractC5475a f18825a;

        /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
        public C4169b(AbstractC5475a aVar, Qualifier aVar2, AbstractC3435a aVar3) {
            super(0);
            this.f18825a = aVar;
        }

        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, ke.a] */
        @Override // p189gn.AbstractC3435a
        public final AdUtils invoke() {
            return this.f18825a.getKoin().f24118a.m920a().m621a(Reflection.m5499a(AdUtils.class), null, null);
        }
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public NovelNativeADGView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        MutabilityOwnership.m3745m(context, "context");
        MutabilityOwnership.m3745m(attributeSet, "attributeSet");
    }

    private final AdUtils getAdUtils() {
        return (AdUtils) this.f18819c.getValue();
    }

    private final ViewAdgWrapperBinding getBinding() {
        return (ViewAdgWrapperBinding) this.f18817a.getValue();
    }

    /* renamed from: a */
    public void m4657a() {
        getBinding().f5396c.setVisibility(0);
        ADG adg = this.f18818b;
        if (adg != null) {
            adg.start();
        }
    }

    @Override // p404oo.AbstractC5475a
    public Koin getKoin() {
        return AbstractC5475a.C5476a.m3211a(this);
    }

    public void setGoogleNg(GoogleNg googleNg) {
        MutabilityOwnership.m3745m(googleNg, "googleNg");
    }

    public final void setup(String str) {
        MutabilityOwnership.m3745m(str, "locationId");
        ADG adg = this.f18818b;
        if (adg != null) {
            getBinding().f5395b.removeView(adg);
            ViewBindings.m9831f(adg);
        }
        ADG adg2 = new ADG(getContext());
        adg2.setLocationId(str);
        adg2.setUsePartsResponse(true);
        adg2.setReloadWithVisibilityChanged(false);
        adg2.setInformationIconViewDefault(false);
        Context context = adg2.getContext();
        MutabilityOwnership.m3746l(context, "context");
        AdUtils adUtils = getAdUtils();
        ViewAdgWrapperBinding binding = getBinding();
        MutabilityOwnership.m3746l(binding, "binding");
        adg2.setAdListener(new C4167a(context, adg2, adUtils, binding));
        this.f18818b = adg2;
        addView(adg2);
    }
}
